/**
 * Distance joint definition. This requires defining an
 * anchor point on both bodies and the non-zero length of the
 * distance joint. The definition uses local anchor points
 * so that the initial configuration can violate the constraint
 * slightly. This helps when saving and loading a game.
 * @warning Do not use a zero or short length.
**/
public class b2DistanceJointDef extends b2JointDef {

	public b2DistanceJointDef()
	{
		type = b2JointType.e_distanceJoint;
		localAnchorA = new b2Vec2(0.0f, 0.0f);
		localAnchorB = new b2Vec2(0.0f, 0.0f);
		length = 1.0f;
		frequencyHz = 0.0f;
		dampingRatio = 0.0f;
	}

	public void release() {
		localAnchorA.release();
		localAnchorB.release();
	}

	/**Initialize the bodies, anchors, and length using the world anchors.*/
	public void Initialize(b2Body bodyA, b2Body bodyB, b2Vec2 anchorA, b2Vec2 anchorB) {
		this.bodyA = bodyA;
		this.bodyB = bodyB;
		
		jni_b2DistanceJointDef_GetLocalPoint(
			localAnchorA.address, bodyA.address, anchorA.address,
			localAnchorB.address, bodyB.address, anchorB.address
		);

		length = jni_b2DistanceJointDef_length(anchorA.address, anchorB.address);
	}

	/**The local anchor point relative to bodyA's origin.*/
	public b2Vec2 localAnchorA;

	/**The local anchor point relative to bodyB's origin.*/
	public b2Vec2 localAnchorB;

	/**The natural length between the anchor points.*/
	public float length;

	/*The mass-spring-damper frequency in Hertz. A value of 0 disables softness.*/
	public float frequencyHz;

	/**The damping ratio. 0 = no damping, 1 = critical damping.*/
	public float dampingRatio;

	native static void jni_b2DistanceJointDef_GetLocalPoint
	(int localAnchorA, int bodyA, int anchorA, int localAnchorB, int bodyB, int anchorB);

	private native static float jni_b2DistanceJointDef_length(int v1, int v2);
}
